<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header::common_header(~{::title},~{::link},~{})">
    <title>数据日志</title>
    <link rel="stylesheet" href="/css/index.css" type="text/css">
</head>
<body>
<div th:replace="common/bar::topbar" style="height: 100%"></div>
<div class="container-fluid">
    <div class="row">
        <!--左边导航栏-->
        <div th:replace="common/bar::#sidebar"></div>
        <!--//中间表格栏-->
        <div style="float: left;margin:15px">
            <h6 style="margin: 15px;color: darkgray" id="DevDesc"></h6>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    <th scope="col" style="margin-left: 50px;margin-right: 50px ">异常时间</th>
                    <th scope="col">异常设备</th>
                    <th scope="col">设备位置</th>
                    <th scope="col">提醒次数</th>
                    <th scope="col">状态</th>
                </tr>
                </thead>
                <tbody id="t_body">

                </tbody>
            </table>
            <hr/>

            <div class="page">
                <button id="firstPage">首页</button>&#160;&#160;&#160;
                <button id="previous">上一页</button>&#160;&#160;&#160;
                第<input type="text" id="index" value="1" size="1">页&#160;&#160;&#160;
                <button id="next">下一页</button>&#160;&#160;&#160;
                <button id="last">尾页</button>
                <div id="pageCount" style="display: inline-block"></div>
            </div>
        </div>
    </div>
    <!--右边-->
    <div style="float: right">
        <div style="height: 100px;width: 100px"></div>
    </div>

</div>
</div>
</body>
</html>


<script type="text/javascript">
    var pageSize = "5";//每页行数
    var pageIndex = "1";//当前页
    var totalPageCount = "0";//总页数
    var totalCount = "0";//总记录数
    var OriUrl = window.location.pathname
    //jquery代码随着document加载完毕而加载
    $(document).ready(function () {
        //分页查询
        window.onload = queryForPages();

        function queryForPages() {
            $.ajax({
                url: '/handle/api/listAllHandled',
                type: 'get',
                dataType: 'json',
                data: "pageNo=" + pageIndex + "&pageSize=" + pageSize,
                success: function callbackFun(data) {
                    //清空数据
                    clearDate();
                    //查询数据
                    fillTable(data);
                }
            });
        }

        //填充数据
        function fillTable(Jdata) {
            var list = ""
            var trs = "";//不初始化字符串"",会默认"undefined"
            list = Jdata.data
            totalPageCount = list.pages,
                // pageSize=list.size,
                pageIndex = list.pageNum,
                totalCount = 1+pageSize*(pageIndex-1);
            for (var i = 0; i < list.size; i++) {
                var exceptionDate=new Date(list.list[i]['exceptionDate']).toLocaleDateString().replace(/\//g, "-") + " " + new Date(list.list[i]['exceptionDate']).toTimeString().substr(0, 8);
                var checkTime=new Date(list.list[i]['checkTime']).toLocaleDateString().replace(/\//g, "-") + " " + new Date(list.list[i]['checkTime']).toTimeString().substr(0, 8);


                var tr = '<tr><th scope="row">' + totalCount + '</th>' +
                    '<td>' + exceptionDate + '</td>' +
                    '<td>' + list.list[i]['nodeName'] + '</td>' +
                    '<td>' + list.list[i]['desc'] + '</td>' +
                    '<td>' + list.list[i]['exceptionNum'] + '</td>';

                if (list.list[i]['state'] == 1) {
                    tr +=
                        '<td>' + checkTime+ '</td>' +
                        '</tr>';
                }
                if (list.list[i]['state'] == 0) {
                    tr +=
                        '<td>' + '<button class="btn btn-warning" type="button" onclick="check(' + list.list[i]['handleId'] + ')">已检查异常</button>' + '</td>' +
                        '</tr>';
                }

                trs += tr;
                totalCount++;
            }
            $("#t_body").append(trs);

        }



        //清空数据
        function clearDate() {
            $("#t_body").html("");
        }

        //首页
        $("#firstPage").click(function () {
            //var index=$("#index").val();
            pageIndex = "1";
            $("#index").val(pageIndex);
            queryForPages();
        });
        //上一页
        $("#previous").click(function () {
            if (pageIndex > 1) {
                pageIndex--;
            }
            $("#index").val(pageIndex);
            queryForPages();
        });  //下一页
        $("#next").click(function () {
            if (pageIndex < totalPageCount) {
                pageIndex++;
            }
            $("#index").val(pageIndex);
            queryForPages();
        });
        //尾页
        $("#last").click(function () {
            pageIndex = totalPageCount;
            $("#index").val(pageIndex);
            queryForPages();
        });
    });
</script>

<script>
    function check(arr) {
        $.ajax({
            url: '/handle/api/checkHandle',
            type: 'post',
            dataType: 'json',
            data: {
                handleId:arr
            },
            success: function callbackFun(data) {
                alert(data.code + data.message)
                window.location.href = "/handle"
            }
        });
    }
</script>